/**
 *  Author:   张卫明
 *  Date:     2015-5-22
 *  Description: 通用 工具类
*/

;(function($,window,ECar){

	ECar.Tool = {};

	/**
	 * 判断是否为IE
	 */

	ECar.Tool.isIE6 = /msie 6/i.test(navigator.userAgent);
	ECar.Tool.isIE7 = /msie 7/i.test(navigator.userAgent);
	ECar.Tool.isIE8 = /msie 8/i.test(navigator.userAgent);
	ECar.Tool.isIE = /msie/i.test(navigator.userAgent);

	/**
	 * indexOf 兼容IE
	 */
	if(!Array.indexOf)
	{
	    Array.prototype.indexOf = function(obj)
	    {
	        for(var i=0; i<this.length; i++)
	        {
	            if(this[i]==obj)
	            {
	                return i;
	            }
	        }
	        return -1;
	    };
	}

})(jQuery,window,window.ECar||(window.ECar={}));


var feedbookEle = $('#feedbook'),feedbookHtml = feedbookEle.html();
;(function($,window,ECar){

    window.sidebar = {
	config: {
		eleFeed:	$('#js_cmp_enter')
	},
	init: function () {

		var _this = this;

		this.submitFeed();
	},
	openFeedbook:function(){
		// 调用快速登录
		backCallName = 'sidebarFeedbook';
		if( typeof(checkLogin)!='undefined' && typeof(checkLogin) == 'function'){
			checkLogin(MALL.accountQuickBase,'B');
		}
	},

	submitFeed: function(){
		var _this = this;
		//feedbookEle.remove();
		_this.config.eleFeed.on('click', function () {
            _this.openFeedbook();
		});

		//mouseover 动画
		//this.eleAnimate(this.config.eleFeed);

	},
	 //提交按钮事件
    	openFun:function(){

		$('#submitFeed').on('click' , function(){

			var $feedTypeValue = getRadioValue('feedbackType'),$questionValue = $.trim($('#question').val().replace(/\n/g,"@@@@"));

			if(!$feedTypeValue){
			    $('.submit-error').html('请选择反馈类型');
			    return false;
			}

			if($questionValue == ''){
			    $('.submit-error').html('请填写意见');
			    return false;
			}

			var $data = {
			    'feedbackType' : $feedTypeValue,
			    'question'		: $questionValue
			};


			$.ajax({
				url	:'/member/addFeedback.htm',
				type:'post',
				data:$data,
				success:function(data){
					if(data == 'true'){
						ECar.easyDialog.close();
						ECar.easyDialog.open({
							container : {
							    header : '提交反馈',
							    content : '<div style="text-align:center">提交成功</div>'
							},
							autoClose:3000,
							callback:function(){
								if(!hasLogin){
								window.location.reload(true);
								}
							}
						});
					} else {
						ECar.easyDialog.close();
						ECar.easyDialog.open({
							container : {
							    header : '提交反馈',
							    content : '<div style="text-align:center">提交失败</div>'
							},
							autoClose:3000,
							callback:function(){
								if(!hasLogin){
								window.location.reload(true);
								}
							}
						});
					}
				},
				error:function(){

				}
			});

	            });

	            //获取反馈类型
	            function getRadioValue(name){
				var radioes = document.getElementsByName(name);
				for(var i=0;i<radioes.length;i++){
					if(radioes[i].checked){
						return radioes[i].value;
					}
				}
			return false;
		}

        	}
    };
    $(document).ready(function(){
    	window.sidebar.init();
    });

})(jQuery,window,window.ECar||(window.ECar={}));

/* Author:   张卫明
* Date:     2015-6-1
* Description: tooltip js
*/
;(function($,window,ECar){

	ECar.tooltip = function(){

		//生成tooltip结构
		var $tool = $("*[tooltip]"),
			$toolHtml = '<div class="tooltip" id="tooltip"><p id="tooltip-content"></p><div class="tooltip-i"><i></i></div></div>';
		$('body').append($toolHtml);

		var _tooltip = $('#tooltip'),
			_content = $('#tooltip-content'),
			_toolArrow = $('.tooltip-i','#tooltip'),
			TipAutoHideID = 0;

		//为tooltip添加事件
		$tool.each(function(){
			var elem = $(this);

			$(this).hover(function(event) { //show

				updateContent(elem);

                updatePosition(event,elem);

                _tooltip.show().animate({opacity:0.9});

				if (TipAutoHideID>0){
					clearTimeout(TipAutoHideID);
					TipAutoHideID = 0;
				}
				TipAutoHideID = setTimeout(function(){
					_tooltip.hide().css({opacity:0.3});
				},100000);

            },function() { 					// Hide

				updateContentBack(elem);
				_tooltip.hide().css({opacity:0.3});
				if (TipAutoHideID>0){
					clearTimeout(TipAutoHideID);
					TipAutoHideID = 0;
				}

            });

		});

		var setPosition = function(posX, posY) {
			_tooltip.css({ left: posX, top: posY });
        };

		/*更新 tooltip 位置 */
		var updatePosition = function(event,elem) {

			var $thisArrow = (elem.attr('arrow') =='bottom' ? 'bottom':'top'),
				$thisHeight = elem.height(),
				tooltipWidth = _tooltip.outerWidth(),
				tooltipHeight = _tooltip.outerHeight(),
				$window = $(window),
				windowWidth = $window.width() + $window.scrollLeft(),
				windowHeight = $window.height() + $window.scrollTop(),
				posX = elem.offset().left+elem.innerWidth()/2 - tooltipWidth/2;

            if($thisArrow == 'bottom'){
            	var posY = elem.offset().top + $thisHeight+6;
				_toolArrow.attr('class','tooltip-i tooltip-i-b');
			} else {
            	var posY = elem.offset().top - tooltipHeight-6;
				_toolArrow.attr('class','tooltip-i tooltip-i-t');
			}

            setPosition(posX,posY);

        };

		/*构建 tooltip内容 */
		var updateContent= function(elem) {
			_content.html(elem.attr('tooltip'));
		};

		/*清除 tooltip内容 */
		var updateContentBack = function(elem) {
			_content.html('');
		};

	};

})(jQuery,window,window.ECar||(window.ECar={}));

/* Author:   张卫明
* Date:     2015-5-22
* Description: 快速登录 js
*/

window.backCallName = '';
/**快速注册登录成功后的回调函数*/

window.backCallFun = function(obj){

	//注册登录成功后的后续操作

	switch (backCallName) {
		/* 详情页 */
		case 'goPreOrder':
			detailPage.goPreOrderDetail();
			break;
		case 'goPayCar':
			detailPayCar.goPreOrderDetail();
			break;
		case 'goAddCollection':
			detailPage.goAddCollectionDetail();
			break;
		case 'goCancelCollection':
			detailPage.goCancelCollectionDetail();
			break;
		/* 通用侧边栏  */
		case 'sidebarFeedbook':
			ECar.easyDialog.open({
				container : {
				    header : '提交反馈',
				    content : feedbookEle
				},
				success: sidebar.openFun
			});

			break;
		case 'sidebarMyCollect':
			window.sidebar._myCollect();
			break;
		case 'submitConsult':
			buyAskList.submitConsultHandle();
			break;
		default:
			window.location.reload(true);
			break;
	};
	if(ecarHd){
		ecarHd.getLoginInfo();
	}
};


/*豆腐块 标签垂直居中*/

;(function($,window,ECar){

	if(ECar.Tool.isIE7 || ECar.Tool.isIE6){
		var $lab = $('.lab-zj');
		$lab.each(function(){
			var $labHtml=$(this).html();
			$(this).html('<span class="ieLab">'+$labHtml+'</span>');

		});

		$('.ieLab').each(function(){
			var ieHe = $(this).height();
			$(this).css({'top':'50%','margin-top':-1*ieHe/2+'px'});
		});
	};

})(jQuery,window,window.ECar||(window.ECar={}));